Ext.define('Mis.controller.DemoController', {
    extend: 'Ext.app.Controller',
    GridDoActionUtil : Ext.create("util.GridDoActionUtil"),
    requires: ['Ext.ComponentQuery'],
    init: function() {
    	var me = this;
    	me.getGridObj = function(button) {
			return button.ownerCt.ownerCt;
		};
		me.getFormObj = function(button) {
			return button.ownerCt.ownerCt;
		};
        me.control({
            'demogrid button[action=add]': {
            	click : function(addbutton) {
            		var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait...",removeMask:true});
//					myMask.show();
            		win = Ext.create('Mis.view.demo.DemoWindow').show();
				}
            },
            'demogrid button[action=update]': {
                click : function(updatebutton) {
                	var grid = me.getGridObj(updatebutton);
			        var data=grid.getSelectionModel().getSelection();
			        if(data.length!=1){
						Ext.Msg.alert("提示","只能选择一条数据进行修改！");
					}else{
			        	var selection = data[0];
			        	var win = Ext.create('Mis.view.demo.DemoWindow').show();
			        	win.down('form').loadRecord(selection);
					}
				}
            },
            'demogrid button[action=remove]': {
                click : function(deletebutton) {
                	var grid = me.getGridObj(deletebutton);
					me.GridDoActionUtil.doDelete(grid);
				}
            },
            'demogrid button[action=refresh]': {
                click : function(refreshbutton) {
					var grid = me.getGridObj(refreshbutton);
					var store = grid.getStore();
					store.loadPage(1);
                }
            },
            'demoform button[action=submit]': {
            	click : function(submitbutton) {
            		var grid = Ext.ComponentQuery.query("grid[modelId=demo]")[0];
            		this.GridDoActionUtil.doSaveOrUpdate(grid,submitbutton);
            	}
            },
            'demoform button[action=cancel]': {
            	click : function(cancelbutton) {
            		var win = cancelbutton.up('window');
            		win.close();
            	}
            }
        });
    }
});
